﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcmyjobs.Web.admininfo
{
    public partial class Modify : Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["admin_id"] != null)
                {
                    int aid = (Convert.ToInt32(Session["admin_id"]));
                    ShowInfo(aid);
                }
                else
                {
                    Maticsoft.Common.MessageBox.ResponseScript(this, "alert('请先登陆！');top.location.href='../adminlogin2.aspx'");
                }

            }
        }

        private void ShowInfo(int aid)
        {
            lcmyjobs.BLL.admininfo bll = new lcmyjobs.BLL.admininfo();
            lcmyjobs.Model.admininfo model = bll.GetModel(aid);
            this.lblaid.Text = model.aid.ToString();
            this.txtaname.Text = model.aname;
            this.txtapwd.Text = model.apwd;
            this.txttruename.Text = model.truename;

            DataSet ds = new lcmyjobs.BLL.admin_type().GetList("");

            this.ddl_atid.DataSource = ds;
            this.ddl_atid.DataTextField = "atname";
            this.ddl_atid.DataValueField = "atid";

            this.ddl_atid.DataBind();

            this.ddl_atid.SelectedValue = model.atid.ToString();
        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtaname.Text.Trim().Length == 0)
            {
                strErr += "用户名不能为空！\\n";
            }
            if (this.txtapwd.Text.Trim().Length == 0)
            {
                strErr += "密码不能为空！\\n";
            }


            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int aid = int.Parse(this.lblaid.Text);
            string aname = this.txtaname.Text;
            string apwd = this.txtapwd.Text;
            apwd = myPublic.GetMd5(apwd);
            int atid = int.Parse(this.ddl_atid.SelectedItem.Value);


            lcmyjobs.Model.admininfo model = new lcmyjobs.Model.admininfo();
            model.aid = aid;
            model.aname = aname;
            model.apwd = apwd;
            model.atid = atid;
            model.truename = this.txttruename.Text;

            lcmyjobs.BLL.admininfo bll = new lcmyjobs.BLL.admininfo();
            bll.Update(model);
            Maticsoft.Common.MessageBox.Show(this, "保存成功！");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
